$(function(){
	$.ajax({
		url : '/Lvscore_Advertiser_Maven/gainBankImg',	
		data : {},
		type : 'post',
		dataType:"json",
		success : function(json){
			var bankImg=json.count;	
			$("#bankImg").addClass(" bankImgPos"+bankImg)
			$("#bankName").html(json.bankName);
			$("#money").val(json.money);			
			}
	});
	
	$("#checkbox").on("click",function(){
		var checkboxVal=$("input[type='checkbox']").is(':checked')
		if(checkboxVal){
			$("#submit").attr("disabled",false);
		}else{
			$("#submit").attr("disabled",true);
		}
	});	
	
	
});

//发送手机验证码
$("#sendCode").click(function(){
	$("#error_code").html("");//提示框置为空
	if(checkBankPhone){
		var bankPhone=$("#bankPhone").val();
		$.ajax({
			url:'/Lvscore_Advertiser_Maven/sendPhoneCode',
			type:"POST",
		    dataType:"json",
		    data:{"bankPhone":bankPhone},
		    success:function(json){
		    	if (json.status == -1) { // 
					$("#error_code").val(json.error);
				}else{
					timeGo();//倒计时
				}
		    },
		    	
		});
	}else{
		$("#error_phone").html("*请输入有效手机号")
	}
});

var countdown;
var timer=null;
/**
 * 倒计时
 * @returns
 */
function timeGo(){
	 countdown=60;	
	 $("#sendCode").attr("disabled",true);
	 timer=setInterval(function(){
			countdown--;		
			$("#sendCode").html(countdown+'s');
			if (countdown <= 0) {
				$("#sendCode").html("重新获取");
				clearInterval(timer);
				$("#sendCode").attr("disabled",false);
		
			}
	 }, 1000);	
}




var checkCardName = false;
var checkBankPhone = false;
var checkPhoneCode = false;

//校验银行卡号
$("#cardName").blur(
		function(){
			var reg = /^(\d{16}|\d{19})$/g;
			var cardName = $("#cardName").val();
			if(reg.test(cardName)){
				$("#error_card").html("");
				checkCardName = true;
			}else{
				$("#error_card").html("*请输入16位或19位卡号");
			}
		}	
)
//检验银行预留手机号
$("#bankPhone").blur(
		function(){  //手机号
			var mobilePhone = /^[1][3578][0-9]{9}$/;
			var bankPhone = $("#bankPhone").val();
			if(mobilePhone.test(bankPhone)){
				$("#error_phone").html("");
				checkBankPhone = true;		
			}else{
				$("#error_phone").html("*请输入有效手机号")
			}
		}
)
//检验验证码是否是空
$("#phoneCode").blur(
		function(){  
			var error_code = $("#phoneCode").val();
			if(null!=error_code && ""!=error_code){
				$("#error_code").html("");
				checkPhoneCode = true;		
			}else{
				$("#error_code").html("*不能为空");
			}
		}
)

$("#submit").click(function(){
	if(checkCardName){
		if(checkBankPhone){
			if(checkPhoneCode){
				var money = $("#money").val(), bankPhone=$("#bankPhone").val(),phoneCode=$("#phoneCode").val();
				var param = {"money" : money,"bankPhone":bankPhone,"phoneCode":phoneCode,"pwd":""};
					$.ajax({
						url:'/Lvscore_Advertiser_Maven/updateBalance',
						type:"POST",
					    dataType:"json",
					    data:param,
					    success:function(json){
					    	if (json.status == 1) { 
					    		var path=escape('selectedNav=0&navPos=3');
					    		window.location.href = "/Lvscore_Advertiser_Maven/advertiserWeb/views/userCenter/recharge/saveSuccess.html?"+path;
							}else{
								$("#error_code").html(json.error);
							}
					    },
					});	
			}else{
				$("#error_code").html("*不能为空");
			}
			
		}else{
			$("#error_phone").html("*请输入有效手机号")
		}
	}else{
		$("#error_card").html("*请输入19位卡号");
	}
	
});







